# IO 操作 ：
#  读 写 追加

# open

# 写操作
# open_operator = open("../data/write_ope.txt", mode='x', encoding="UTF8")
# open_operator.write("这是一个字符串....\n")
# open_operator.write("这是一个字符串....\n")
# open_operator.writelines("这是一个字符串....\n")
# open_operator.writelines("这是一个字符串....\n")
# open_operator.close()


# list = ["1", "2", "这是一个字符串"]
# write_operator = open("../data/write_ope.txt", mode='x', encoding="UTF8")
# # open_operator.write(list)  # write只能传入单个字符串
# write_operator.writelines(list)  # writelines可以传入一个集合，但是集合中要求元素必须为字符串
# write_operator.close()


# write_operator = open("../data/append_ope.txt", mode='w', encoding="UTF8")
# write_operator.write("这是一个字符串....\n")
# write_operator.write("这是一个字符串....\n")
# write_operator.close()


append_operator = open("../data/append_ope.txt", mode='a', encoding="UTF8")
append_operator.write("这是一个字符串....\n")
append_operator.write("这是一个字符串....\n")
append_operator.write("这是一个字符串....\n")
append_operator.close()

read_operator = open("../data/append_ope.txt", mode='r', encoding="UTF8")
for line in read_operator.readlines():
    print(line)
read_operator.close()

# with ..  as .. 针对 as 保存的对象，with会帮助我们自动做close操作，只要对象中有close函数
with open("../data/append_ope.txt", mode='r', encoding="UTF8") as read_operator:
    for line in read_operator.readlines():
        print(line)
   